package lc.动态规划;

import java.util.HashSet;
import java.util.Set;

/**
 * @description:
 * @author: qian
 * @createDate: 2021/10/21
 */
public class 剑指Offer48_最长不含重复字符的子字符串 {

    public int lengthOfLongestSubstring(String s) {

        int max = -1;
        int start = 0;
        Set<Character> set = new HashSet();
        for (int end = 0; end < s.length(); end++) {

            while (set.contains(s.charAt(end))) {
                set.remove(s.charAt(start));
                start++;
            }
            max = Math.max(max,end - start +1);
            set.add(s.charAt(end));
        }
        return max;
    }
}
